/* test：自发自收测试 */
// let count = 60

/* 解析函数 */
function parserBDPWI(arrayData, port, config, server) {
	// 无信号时候$BDPWI,000000.00,00,00*4A
	// $BDPWI,070015.36,04,02,50,50,01,46,46,08,43,43,05,53,53,00*46-4,7,10,13
	if (arrayData[1] == '000000.00') {
		console.log('bd短报文模块未搜索到波束，请检查，尽量不要在室内...')
		let res = { resCount: 0 }
		server.send(JSON.stringify(res), config.udpServerSendPort, config.udpServerGB)
	} else {
		let trueCount = 0
		let status1 = arrayData[4] && +arrayData[4]
		if (status1 >= 45) {
			trueCount++
		}
		let status2 = arrayData[7] && +arrayData[7]
		if (status2 >= 45) {
			trueCount++
		}
		let status3 = arrayData[10] && +arrayData[10]
		if (status3 >= 45) {
			trueCount++
		}
		let status4 = arrayData[13] && +arrayData[13]
		if (status4 >= 45) {
			trueCount++
		}
		let res = { resCount: trueCount, wx1: status1, wx2: status2, wx3: status3, wx4: status4 }
		// udp传出去格式：{ resCount: 4, wx1: 52, wx2: 50, wx3: 46, wx4: 45 }
		server.send(JSON.stringify(res), config.udpServerSendPort, config.udpServerGB)
	}

	/* 自发自收测试代码 */
	// @@@测试代码-自发自收测试
	// if (count > 60) {
	// 	port.write(
	// 		'$BDTCQ,1002008,1,2,2,11A14A08A30B627177A104B036132A0B181A17B1A2A527B6312A8A0B74AF0B19AF75B83A1C11A14A39A30B627177A104B036132A0B179A197B2A2A527B6306A8A0B73AF0B18AF75B92A1,0*0C\r\n'
	// 	)
	// 	port.drain(() => {
	// 		console.log('bd发送测试数据...')
	// 	})
	// 	count = 0
	// }
	// count++
}

module.exports = parserBDPWI
